/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mamesoft.namibiamc.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author simone
 */
public class NoSuggestValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String input = (String) value;
        boolean matchFound = false;
        try {
            matchFound = Integer.parseInt(input.split(" ")[0]) >= 0;
        } catch (NumberFormatException e) {
            matchFound = false;
        }

        if (!matchFound) {
            FacesMessage message = new FacesMessage();
            message.setDetail("Usa i suggerimenti o inserisci l'id");
            message.setSummary("Usa i suggerimenti o inserisci l'id");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(message);
        }
    }
}
